package com.xbongbong.pro.statistic.pojo;

import com.xbongbong.paas.enums.RelatedPersonnelEnum;
import com.xbongbong.paas.enums.VisibleTypeEnum;
import com.xbongbong.paas.field.VisibleRulePoJo;
import com.xbongbong.paas.field.VisibleRuleVO;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.sys.enums.RoleEnum;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author zcp
 * @version v1.0
 * @since v1.0
 */
@Getter
@Setter
@ToString
@NoArgsConstructor
public class DataSetPermissionPojo implements Serializable {
    private static final long serialVersionUID = -5981797705927554333L;

    /**
     * 编辑者权限
     */
    private VisibleRulePoJo editableRule;
    /**
     * 查看者权限
     */
    private VisibleRulePoJo visibleScopeRule;
    public DataSetPermissionPojo(UserVO loginUser){
        //把创建人、超管初始化至查看者权限、编辑者权限
        List<VisibleRuleVO> userVoList = new ArrayList<>();
        //id、userId都是创建人的userId
        userVoList.add(new VisibleRuleVO(loginUser.getUserId(), loginUser.getUserId(), loginUser.getName()));
        VisibleRulePoJo editableRule = new VisibleRulePoJo();
        editableRule.setRole(Arrays.asList(RoleEnum.ADMIN.getCode()));
        editableRule.setType(VisibleTypeEnum.SOME_PEOPLE_CAN_SEE.getType());
        editableRule.setRelative(Arrays.asList(RelatedPersonnelEnum.CREATOR.getType()));
        List<String> userList = new ArrayList<>();
        userList.add(loginUser.getUserId());
        editableRule.setUser(userList);
        editableRule.setUserList(userVoList);
        VisibleRulePoJo visibleScopeRule = new VisibleRulePoJo();
        visibleScopeRule.setRole(Arrays.asList(RoleEnum.ADMIN.getCode()));
        visibleScopeRule.setType(VisibleTypeEnum.SOME_PEOPLE_CAN_SEE.getType());
        visibleScopeRule.setRelative(Arrays.asList(RelatedPersonnelEnum.CREATOR.getType()));
        visibleScopeRule.setUser(userList);
        List<VisibleRuleVO> userVoList2 = new ArrayList<>();
        userVoList2.add(new VisibleRuleVO(loginUser.getId(), loginUser.getUserId(), loginUser.getName()));
        visibleScopeRule.setUserList(userVoList2);
        this.editableRule = editableRule;
        this.visibleScopeRule = visibleScopeRule;
    }
}
